package cn.whdream.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池：提供一个线程队列。避免了创建和销毁额外的开销，提高响应的速度。
 * @author admin
 *
 */
public class TestThreadPool {
	public static void main(String[] args) {
		ExecutorService pool = Executors.newFixedThreadPool(5);
		ThreadDemo demo = new ThreadDemo();
		for (int i = 0; i < 10; i++) {
			pool.submit(demo);
		}
		pool.shutdown();
	}
	
	private static class ThreadDemo implements Runnable{

		private int i;

		@Override
		public void run() {
			while (i <= 100) {
				System.out.println(Thread.currentThread().getName()+"ThreadDemo: "+i++);
			}
		}
		
	}
}
